home *** CD-ROM | disk | FTP | other *** search
/ Apple Service Training: … to Apple Monitor Service / Introduction to Apple Monitor Service v1.0 1994.iso / Additional Goodies / TechInfo Documents / Grayscale Information < prev    next >
Encoding:
Text File  |  1994-02-10  |  10.6 KB  |  208 lines  |  [TEXT/GEOL]

  1. Grayscale Information
  2.  
  3. Article Created: 23 April 1989
  4. Article Last Reviewed: 6 July 1992
  5. Article Last Updated:
  6.  
  7. TOPIC -----------------------------------------------
  8.  
  9. A user has found (using very sophisticated photometric devices) that when
  10. he generates a monochrome palette from a color palette, some of the tones
  11. are identical.  This article discusses this phenomenon.
  12.  
  13. DISCUSSION ------------------------------------------
  14.  
  15. In regard to using the color palette, the Palette Manager does not place
  16. new colors into the display device's color look-up table (CLUT).  It maps
  17. the requested colors in a palette to available colors within the current
  18. color table.  The correct method for using specific color values is to use
  19. the Color Manager calls to create and load a programmed color table.
  20.  
  21. There are some other points that must taken into account after setting
  22. your colors with the Color Manager.
  23.  
  24. - It is possible to produce grays by setting the monitor to monochrome
  25. output and not setting grays, as the user in question probably does.  When
  26. selecting monochrome from the monitor's Control Panel CDEV, luminance
  27. mapping of the colors in the color table is done to calculate and replace
  28. the RGB values for a monochrome pixel.  The luminance mapping follows this
  29. equation:
  30.  
  31.    Luminance = .3*red + .59*green + .11*blue
  32.  
  33. The resulting value is placed into the display device's table for R, G,
  34. and B.  The values are altered according to the above equation. This needs
  35. to be taken into account if the monochrome option is chosen for the Apple
  36. High-Resolution Color Monitor.
  37.  
  38. - If you place your own RGB "gray" values into a color table, you must
  39. also take into account gamma correction. Gamma correction is done by the
  40. display device's driver to correct the disproportionate light output of
  41. the CRT phosphors by comparison with the proportional input voltages of
  42. the video signal.  To set a linear relationship between colors and output,
  43. the values set for the Macintosh II Video Card are changed to new values,
  44. which then produce the corrected color output on the monitor. Test
  45. equipment detects a gamma-filtered set of values from the monitor.
  46.  
  47. The gamma correction is automatically handled for all values written to
  48. the device's color table.  This is based on an empirically-derived gamma
  49. look-up table. If the selected values fall within the same look-up table
  50. reference, they can be mapped to the same gamma value.  This would explain
  51. why some values are the same.   The gamma table ID is located in the SCRN
  52. resource of the System file for the Macintosh II Video Card. A new GAMA
  53. Resource table can be defined and installed in the System file for use by
  54. the Macintosh II Video Card. To use the new gamma table, the GAMA resource
  55. ID must be changed in the SCRN resource to that of the new table.
  56.  
  57. The safest values for any testing will probably be a linear table that
  58. does no gamma correction.  A quick and easy way to do this is to pass -1
  59. to the SetGamma Control parameter block as the new table address.  This
  60. causes a linear table to be used, guaranteeing that all of the possible
  61. gray levels of the card are available.  At that point, the actual color
  62. output on the monitor depends on the phosphors themselves, which have a
  63. variance from monitor to monitor of +/-.02 for the red and green phosphors
  64. and +/-.015 for the blue. The CIE coordinates of the phosphors are:
  65.  
  66.    Red: x=.625 y=.34 Green: x=.28   y=.595 Blue:     x=.155 y=.070
  67.  
  68. To properly set the gamma table, see the information below about how the
  69. driver uses this table.  You should also investigate how to control device
  70. drivers. This is described in "Inside Macintosh Volume II." Another source
  71. of information is the "Designing Cards and Drivers Manual for the
  72. Macintosh."
  73.  
  74. Gamma Information
  75. -----------------
  76. In the current implementation of the video drivers, gamma correction is
  77. applied to requested, absolute colors, immediately before they are set in
  78. the color look-up table by the SetEntries control call. More specifically,
  79. some number of high-order bits are extracted from the red, green, and blue
  80. channels and used as an index into tables of corrected values.  These
  81. values are then placed into the hardware, yielding corrected output. On
  82. the Macintosh II Video Card (the TFB card), the high eight bits of each
  83. channel are used to reference the gamma table.
  84.  
  85. There are a number of minor shortcomings in this implementation. First,
  86. there is not absolute symmetry between the SetEntries control call, which
  87. sets the CLUT, and the GetEntries status call, which reads the CLUT
  88. hardware, because the gamma correction took place as part of the
  89. SetEntries call. Also, the uncorrected values are generally unrecoverable
  90. (although a copy of the absolute colors are always available in the
  91. GDevice structure).
  92.  
  93. Finally, it is most desirable to extract more bits as an index to the
  94. gamma table than the number of bits of color information that will be set
  95. in the CLUT.  This way, you avoid a loss of color resolution after
  96. correction. For example, the TFB card has an eight-bit-per-channel CLUT,
  97. but only uses the most-significant eight bits of the (16-bit) channel
  98. information for gamma lookup. At lower intensities, the gamma correction
  99. increases the distance between adjacent values.  As a result, on the TFB
  100. card, some dynamic range is lost at lower intensities. This could be
  101. corrected by extracting nine or ten bits of channel information rather
  102. than eight and using a larger, gamma-correction table, but this option was
  103. declined to reduce gamma table size.
  104.  
  105. The GammaTbl Data Structure
  106. ---------------------------
  107. The structure itself has been a bit of a mystery, as it is not defined in
  108. either "Inside Macintosh Volume V" or the Designing Cards and Drivers
  109. Manual. This is the structure:
  110.  
  111.    record GammaTable of
  112.    gVersion: integer; {gtab version, currently 0}
  113.    gType: integer; {drHwId value}
  114.    gFormulaSize: integer; {size of formula data, below}
  115.    gChanCnt: integer; {# of component channels}
  116.    gDataCnt: integer; {# of values per channel}
  117.    gDataWidth: integer; {size of data in tables}
  118.    {gamma correction look-up tables}
  119.    gFormulaData: array [0.. gFormulaSize] of byte;
  120.    {data for gamma calculation formula}
  121.    gData: array [0.. gDataCnt] of byte;
  122.    end;
  123.  
  124. In this structure, gVersion represents the gamma table format version,
  125. which is 0 for all current cards.  The gType field holds the drHwId value
  126. for this board to identify the board that this table was measured for.
  127. Note that this means that a single gamma table can't directly be shared
  128. between two different cards, even if they both have the same CLUT response
  129. curve (which is usually linear).  This lets the data in the gamma table be
  130. in an appropriate form for varying hardware (that is, a card could have
  131. four-bit/channel DACs and might prefer gamma data in the range $0..$F
  132. rather than $0..$FF).
  133.  
  134. gFormulaSize defines the number of bytes occupied by the gFormulaData
  135. field. On Apple's current video cards, gamma correction is done by
  136. modifying the values loaded into the CLUT by the SetEntries control call
  137. to approximate linear response on the display.  On these systems, the
  138. gamma correction table acts as a final, look-up, data table, which
  139. translates the requested color into closest available linearized level.
  140. These gamma table values are determined empirically by measuring the
  141. output of a calibrated display.
  142.  
  143. More sophisticated systems may choose an alternative to this simple
  144. look-up mechanism.  For instance, you can calculate gamma correction
  145. factors based on a mathematical response function. By default, the TFB
  146. card uses a single correction table for all three channels. No
  147. calculations are performed on the incoming color table other than simple
  148. lookup.  Cards can remember the specific monitor configuration at the
  149. beginning of the gFormulaData field, allowing it to identify and use only
  150. gamma tables developed for the currently connected monitor.
  151.  
  152. gChanCnt is the number of look-up tables in gData, below. If there is more
  153. than one channel of gamma correction data, then the R, G, and B tables
  154. follow each other, respectively, at the end of the structure.
  155.  
  156. gDataCnt is the number of discrete look-up values included in each of the
  157. channel's correction table.  It is always equal to 2gDataWidth, but refers
  158. to number of bytes that this channel's data occupies.
  159.  
  160. gDataWidth describes the number of significant bits of information
  161. available in each entry in a channel's correction table. The data always
  162. appears as gDataWidth bits, right-justified in a field that is the next
  163. larger number of bytes than gDataWidth.  Because it is rare to have
  164. devices with more than eight bits of CLUT resolution, virtually all
  165. devices pack their correction data into bytes.
  166.  
  167. gData is actual correction table data. If there is more than one channel's
  168. information, each table follows the next in R, G, B order. The standard
  169. tables included in Apple's driver have only one table, which is applied to
  170. all three output channels.  Because Pascal cannot express variable size
  171. fields in record structures, the independent channels are not individually
  172. named.
  173.  
  174. "gama" Resource Format
  175. ----------------------
  176. In addition to the RAM data structure for gamma tables covered above,
  177. there is a standard resource format for gamma table resources.  Like many
  178. other resource templates, the gamma structure is an image of the RAM form
  179. stored in resource format. There are no changes.
  180.  
  181. Using Gamma Correction
  182. ----------------------
  183. Gamma correction is always applied by the TFB video driver. At driver open
  184. time, the driver is usually initialized with a linear (noncorrecting)
  185. gamma table.  When _InitGraf is called, the "scrn" screen configuration
  186. resource is read from the System file. This resource (described in "Inside
  187. Macintosh Volume V") includes information about the size and orientation
  188. of the different monitors configured into the system, including their last
  189. video mode (pixelsize), color table, and gamma table.
  190.  
  191. If there is no "gama" resource ID specified, or the specified ID is not
  192. present, then a default gamma table, "gama" =0 is loaded from the System
  193. file and used (this is the table calculated for the TFB card). If the
  194. specified resource is found, then the appropriate resource is loaded, and
  195. a control call is issued to the driver to make this the current gamma
  196. table. Unfortunately, there is currently no tool to set the "gama" ID,
  197. short of modifying the "scrn" resource directly.
  198.  
  199. To facilitate the use of the gamma table, there are two calls in the
  200. standard, video-driver routines that set the gamma table (control call 4,
  201. SetGamma) and retrieve the pointer to the current gamma table (status call
  202. 6 on TFB rev 2 drivers and up). These calls simply take and return a
  203. pointer to a GammaTbl structure.
  204.  
  205.  
  206. Copyright 1991 Apple Computer, Inc.
  207.  
  208.